package com.jingdianjichi.subject.infra.basic.service.impl;

import com.jingdianjichi.subject.infra.basic.entity.SubjectMapping;
import com.jingdianjichi.subject.infra.basic.mapper.SubjectMappingDao;
import com.jingdianjichi.subject.infra.basic.service.SubjectMappingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.List;

/**
 * 题目分类关系表(SubjectMapping)表服务实现类
 *基础设施层的服务层
 * @author makejava
 * @since 2025-07-13 10:55:27
 */
@Slf4j
@Service("subjectMappingService")
public class SubjectMappingServiceImpl implements SubjectMappingService {
    @Resource
    private SubjectMappingDao subjectMappingDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SubjectMapping queryById(Long id) {
        return this.subjectMappingDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param subjectMapping 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */


    /**
     * 新增数据
     *
     * @param subjectMapping 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(SubjectMapping subjectMapping) {

        return  this.subjectMappingDao.insert(subjectMapping);
    }

    /**
     * 修改数据
     *
     * @param subjectMapping 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectMapping update(SubjectMapping subjectMapping) {
        this.subjectMappingDao.update(subjectMapping);
        return this.queryById(subjectMapping.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.subjectMappingDao.deleteById(id) > 0;
    }

    /**
     * 根据分类id查询mapping
     *
     * @param subjectMapping
     */
    @Override
    public List<SubjectMapping> queryLabelIdList(SubjectMapping subjectMapping) {

        return subjectMappingDao.queryDistinctLabelId(subjectMapping);
    }

    @Override
    public List<Long> querySubjectIdsByCategoryIdAndLabelId(Long categoryId, Long labelId) {
        if(log.isInfoEnabled()){
            log.info("SubjectMappingServiceImpl.querySubjectIdsByCategoryIdAndLabelId.categoryId:{}",categoryId);
            log.info("SubjectMappingServiceImpl.querySubjectIdsByCategoryIdAndLabelId.labelId:{}",labelId);
        }
        SubjectMapping subjectMapping = new SubjectMapping();
        subjectMapping.setCategoryId(categoryId);
        subjectMapping.setLabelId(labelId);
        List<Long> result = subjectMappingDao.querySubjectIds(subjectMapping);
        if(log.isInfoEnabled()){
            log.info("SubjectMappingServiceImpl.querySubjectIdsByCategoryIdAndLabelId.result:{}",result);
        }
        return result;
    }

    @Override
    public List<Long> queryLabelIdsBySubjectId(Long subjectId) {
        return subjectMappingDao.queryLabelIdsBySubjectId(subjectId);
    }

    @Override
    public void batchInsert(List<SubjectMapping> mappingList) {
        subjectMappingDao.batchInsert(mappingList);
    }
}
